﻿<UserControl x:Class="OnlineVideos.MemoryGame"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                            xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
                            xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
                            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                            xmlns:memoria_2_Converter="clr-namespace:OnlineVideos.Game;assembly=OnlineVideos.Game"
                            xmlns:memoria_2_Helper="clr-namespace:OnlineVideos.Game;assembly=OnlineVideos.Game"
                            xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                            xmlns:ei="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
                            xmlns:extra="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}"
                            FontSize="{StaticResource PhoneFontSizeNormal}"
                            Foreground="{StaticResource PhoneForegroundBrush}"
                           
                            mc:Ignorable="d"
                            d:DesignWidth="480"
                            d:DesignHeight="480"
                            shell:SystemTray.IsVisible="True"
                            DataContext="{Binding Main, Source={StaticResource Locator}}">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <memoria_2_Helper:CallDatacontextMethodAction MethodName="Start"/>
        </i:EventTrigger>


    </i:Interaction.Triggers>
    <UserControl.Resources>
        <ResourceDictionary x:Key="style">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/OnlineVideos.Game;Component/Theme.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
        <!--<memoria_2_Converter:DifficultyConverter x:Key="DifficultyConverter"/>-->
        <memoria_2_Converter:TimeConverter x:Key="TimeConverter"/>
        <Storyboard x:Name="beginnerAnim">
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="StartGrid">
                <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                    <DiscreteObjectKeyFrame.Value>
                        <Visibility>Visible</Visibility>
                    </DiscreteObjectKeyFrame.Value>
                </DiscreteObjectKeyFrame>
                <DiscreteObjectKeyFrame KeyTime="0:0:0.6">
                    <DiscreteObjectKeyFrame.Value>
                        <Visibility>Collapsed</Visibility>
                    </DiscreteObjectKeyFrame.Value>
                </DiscreteObjectKeyFrame>
            </ObjectAnimationUsingKeyFrames>

            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="StartGrid">
                <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="-410"/>
            </DoubleAnimationUsingKeyFrames>

        </Storyboard>


    </UserControl.Resources>


    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Canvas x:Name="LayoutRoot" 
		Background="Transparent">

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualStateGroup.Transitions>
                    <VisualTransition From="MenuState" GeneratedDuration="0:0:0.6" To="GameState">
                        <VisualTransition.GeneratedEasingFunction>
                            <ElasticEase EasingMode="EaseInOut"/>
                        </VisualTransition.GeneratedEasingFunction>
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="cardListBox">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.6">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>

                        </Storyboard>
                    </VisualTransition>
                    <VisualTransition From="GameState" GeneratedDuration="0:0:0.6" To="EndState">
                        <VisualTransition.GeneratedEasingFunction>
                            <QuinticEase EasingMode="EaseIn"/>
                        </VisualTransition.GeneratedEasingFunction>
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="EndGrid">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.6">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="EndGrid">
                                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="0"/>
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="EndGrid">
                                <EasingDoubleKeyFrame KeyTime="0" Value="-405"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="0"/>
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="EndGrid">
                                <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1"/>
                            </DoubleAnimationUsingKeyFrames>

                        </Storyboard>
                    </VisualTransition>
                    <VisualTransition From="EndState" GeneratedDuration="0:0:0.6" To="MenuState">
                        <VisualTransition.GeneratedEasingFunction>
                            <BackEase EasingMode="EaseInOut"/>
                        </VisualTransition.GeneratedEasingFunction>
                        <Storyboard>
                            <DoubleAnimation Duration="0:0:0.3" To="90" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="EndGrid" d:IsOptimized="True"/>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="EndGrid">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.3">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>

                        </Storyboard>
                    </VisualTransition>
                    <VisualTransition From="PauseState" GeneratedDuration="0:0:0.6" To="GameState">
                        <VisualTransition.GeneratedEasingFunction>
                            <ElasticEase EasingMode="EaseInOut"/>
                        </VisualTransition.GeneratedEasingFunction>
                        <Storyboard>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="PauseGrid">
                                <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="-67.4835"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="-405"/>
                            </DoubleAnimationUsingKeyFrames>
                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PauseGrid">
                                <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0.833374"/>
                                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="0"/>
                            </DoubleAnimationUsingKeyFrames>

                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="cardListBox">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.6">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>

                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PauseGrid">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Visible</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.6">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualTransition>
                    <VisualTransition From="PauseState" GeneratedDuration="0:0:0.6" To="MenuState">
                        <VisualTransition.GeneratedEasingFunction>
                            <BackEase EasingMode="EaseInOut"/>
                        </VisualTransition.GeneratedEasingFunction>
                        <Storyboard>
                            <DoubleAnimation Duration="0:0:0.3" To="90" Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="PauseGrid" d:IsOptimized="True"/>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PauseGrid">
                                <DiscreteObjectKeyFrame KeyTime="0:0:0.3">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>

                            <DoubleAnimation Duration="0:0:0.3" To="0" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="PauseGrid" d:IsOptimized="True"/>

                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="cardListBox">
                                <DiscreteObjectKeyFrame KeyTime="0">
                                    <DiscreteObjectKeyFrame.Value>
                                        <Visibility>Collapsed</Visibility>
                                    </DiscreteObjectKeyFrame.Value>
                                </DiscreteObjectKeyFrame>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualTransition>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="MenuState">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="cardListBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>

                    </Storyboard>
                </VisualState>
                <VisualState x:Name="GameState">
                    <Storyboard>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="EndGrid">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="cardListBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="EndState">
                    <Storyboard>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="EndGrid">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="PauseState">
                    <Storyboard>

                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="PauseGrid">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Visible</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="cardListBox">
                            <DiscreteObjectKeyFrame KeyTime="0">
                                <DiscreteObjectKeyFrame.Value>
                                    <Visibility>Collapsed</Visibility>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <extra:PerformanceProgressBar Width="320" Canvas.Top="710" Foreground="White" RenderTransformOrigin="0.5,0.5" Canvas.Left="80" IsIndeterminate="{Binding IsBusy}" >
            <extra:PerformanceProgressBar.RenderTransform>
                <CompositeTransform ScaleX="1.5" ScaleY="1.5"/>
            </extra:PerformanceProgressBar.RenderTransform>
        </extra:PerformanceProgressBar>
        <ListBox x:Name="cardListBox" Width="440" ItemsPanel="{StaticResource WrapItemsTemplate}" Style="{StaticResource MemoryListBoxStyle}" 
			ItemsSource="{Binding MemoryCardList}" ItemTemplate="{StaticResource MemoryCardDataTemplate}" ItemContainerStyle="{StaticResource CardListBoxItemStyle}" Height="670" VerticalAlignment="Top" Canvas.Left="20" Canvas.Top="{StaticResource GameCanvasTop}" d:LayoutOverrides="Width, HorizontalMargin" Padding="0" Visibility="Visible">
        </ListBox>

        <Grid x:Name="EndGrid" RenderTransformOrigin="0.5,0.5" Width="380" Height="350" Canvas.Left="50" Canvas.Top="140" d:LayoutOverrides="Width, Height" Visibility="Collapsed">
            <Grid.RenderTransform>
                <CompositeTransform/>
            </Grid.RenderTransform>
            <Grid.Projection>
                <PlaneProjection/>
            </Grid.Projection>

            <Rectangle Fill="White"  Stroke="Black" Opacity="0.18" RadiusX="20" RadiusY="20" d:LayoutOverrides="Margin"/>
            <TextBlock x:Name="imagewintext" Text="Congratulations!"  FontSize="38" Width="280" VerticalAlignment="Top" Height="100"  Margin="-10,10,0,0" Visibility="Visible" Foreground="White"></TextBlock>

            <Image x:Name="winimage" HorizontalAlignment="Left" Margin="15,200,0,0"  Source="/Images/Cup.png"  Height="120" Width="120" Visibility="Visible" ></Image>
            <Button x:Name="btnNewGame" Visibility="Visible"  Margin="120,230,0,0"  Style="{StaticResource MemoryButtonStyle}" Width="180" FontSize="32" Background="#FFE5ECF1" Foreground="White" ClickMode="Press" Cursor="Hand" Content=" New game " Height="80"  FontFamily="{StaticResource GameFont}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:GoToStateAction StateName="GameState"/>
                        <memoria_2_Helper:CallDatacontextMethodAction MethodName="Start"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Button.Projection>
                    <PlaneProjection/>
                </Button.Projection>
            </Button>


            <Canvas Height="35" x:Name="endcanvas" Margin="0,100,0,0" VerticalAlignment="Top" Width="270" Visibility="Visible">
                <TextBlock TextWrapping="Wrap" Text="Moves :" FontSize="30" Foreground="White" FontFamily="{StaticResource GameFont}" Canvas.Left="-13" Canvas.Top="1"/>
                <TextBlock TextWrapping="Wrap"  Text="{Binding MoveCounter}" FontSize="30" Foreground="White" FontFamily="{StaticResource GameFont}" Canvas.Left="95" Canvas.Top="1"/>
                <TextBlock TextWrapping="Wrap" Text="{Binding TimeCounter, Converter={StaticResource TimeConverter}}" FontSize="30" Foreground="White" FontFamily="{StaticResource GameFont}" Canvas.Left="225"/>
                <TextBlock TextWrapping="Wrap" Text="Time :" FontSize="30"  Foreground="White" FontFamily="{StaticResource GameFont}" Canvas.Left="140"/>
            </Canvas>
        </Grid>
        <Grid x:Name="PauseGrid" RenderTransformOrigin="0.5,0.5" Width="350" Height="300" Canvas.Left="65" Canvas.Top="234" d:LayoutOverrides="Width, Height" Visibility="Collapsed">
            <Grid.RenderTransform>
                <CompositeTransform/>
            </Grid.RenderTransform>
            <Grid.Projection>
                <PlaneProjection/>
            </Grid.Projection>
            <Rectangle Fill="White" Stroke="Black" Opacity="0.18" RadiusX="20" RadiusY="20" d:LayoutOverrides="Margin"/>
            <Button x:Name="btnResume" Margin="0,0,15,64" Style="{StaticResource MemoryButtonStyle}" Width="145" FontSize="32" Background="#FFE5ECF1" Foreground="White" Cursor="Hand" Content="Resume" Height="80" VerticalAlignment="Bottom" FontFamily="{StaticResource GameFont}" HorizontalAlignment="Right">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <memoria_2_Helper:CallDatacontextMethodAction MethodName="OnResume"/>
                        <ei:GoToStateAction StateName="GameState"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Button.Projection>
                    <PlaneProjection/>
                </Button.Projection>
            </Button>
            <Button x:Name="btnPNew" Margin="15,0,0,64" Style="{StaticResource MemoryButtonStyle}" Width="145" FontSize="32" Background="#FFE5ECF1" Foreground="White" Cursor="Hand" Content="New game" Height="80" VerticalAlignment="Bottom" FontFamily="{StaticResource GameFont}" HorizontalAlignment="Left">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:GoToStateAction StateName="GameState"/>
                        <memoria_2_Helper:CallDatacontextMethodAction MethodName="Start"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <Button.Projection>
                    <PlaneProjection/>
                </Button.Projection>
            </Button>
            <Canvas Height="35" Margin="0,59,0,0" VerticalAlignment="Top" Width="270">
                <TextBlock TextWrapping="Wrap" Text="Moves:" FontSize="32" Foreground="White" FontFamily="{StaticResource GameFont}" Canvas.Top="1"/>
                <TextBlock TextWrapping="Wrap" Text="{Binding MoveCounter}" FontSize="32" Foreground="White" FontFamily="{StaticResource GameFont}" Canvas.Left="94" Canvas.Top="1"/>
                <TextBlock TextWrapping="Wrap" Text="{Binding TimeCounter, Converter={StaticResource TimeConverter}}" FontSize="32" Foreground="White" FontFamily="{StaticResource GameFont}" Canvas.Left="225"/>
                <TextBlock TextWrapping="Wrap" Text="Time:" FontSize="32" Foreground="White" FontFamily="{StaticResource GameFont}" Canvas.Left="156"/>
            </Canvas>
        </Grid>

    </Canvas>
    
</UserControl>